package org.jivesoftware.smack;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;

public class PacketCollector
{
  private PacketFilter packetFilter;
  private ArrayBlockingQueue<Packet> resultQueue;
  private Connection connection;
  private boolean cancelled = false;

  protected PacketCollector(Connection paramConnection, PacketFilter paramPacketFilter)
  {
    this(paramConnection, paramPacketFilter, SmackConfiguration.getPacketCollectorSize());
  }

  protected PacketCollector(Connection paramConnection, PacketFilter paramPacketFilter, int paramInt)
  {
    this.connection = paramConnection;
    this.packetFilter = paramPacketFilter;
    this.resultQueue = new ArrayBlockingQueue(paramInt);
  }

  public void cancel()
  {
    if (!this.cancelled)
    {
      this.cancelled = true;
      this.connection.removePacketCollector(this);
    }
  }

  public PacketFilter getPacketFilter()
  {
    return this.packetFilter;
  }

  public Packet pollResult()
  {
    return (Packet)this.resultQueue.poll();
  }

  public Packet nextResult()
  {
    try
    {
      return (Packet)this.resultQueue.take();
    }
    catch (InterruptedException localInterruptedException)
    {
      throw new RuntimeException(localInterruptedException);
    }
  }

  public Packet nextResult(long paramLong)
  {
    try
    {
      return (Packet)this.resultQueue.poll(paramLong, TimeUnit.MILLISECONDS);
    }
    catch (InterruptedException localInterruptedException)
    {
      throw new RuntimeException(localInterruptedException);
    }
  }

  protected void processPacket(Packet paramPacket)
  {
    if (paramPacket == null)
      return;
    if (this.packetFilter != null)
    {
      if (!this.packetFilter.accept(paramPacket));
    }
    else
      while (!this.resultQueue.offer(paramPacket))
        this.resultQueue.poll();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.PacketCollector
 * JD-Core Version:    0.6.1
 */